#pragma once
#include "Com.hpp"
#include "Protocol.hpp"

class Cal
{
public:
    Cal()
    {

    }
    ~Cal()
    {
        
    }
    Response Execute(Request &req)
    {
        Response res(0, 0);
        switch (req.GetOper())
        {
        case '+':
            res.SetResult(req.GetX() + req.GetY());
            break;
        case '-':
            res.SetResult(req.GetX() - req.GetY());
            break;
        case '/':
        {
            if (req.GetY() == 0)
            {
                res.SetCode(1);
                LOG(LogLevel::WARNNING) << "除0";
            }
            else
            {
                res.SetResult(req.GetX() / req.GetY());
            }
        }
        break;
        case '%':
        {
            if (req.GetY() == 0)
            {
                res.SetCode(2);
                LOG(LogLevel::WARNNING) << "模0";
            }
            else
            {
                res.SetResult(req.GetX() % req.GetY());
            }
        }
        break;
        default:
            res.SetCode(3);
            LOG(LogLevel::WARNNING) << "Unkowed oper";
            break;
        }
        return res;
    }
};